package com.woniu.controller;

import com.woniu.pojo.Log;
import com.woniu.pojo.PageBean;
import com.woniu.pojo.User;
import com.woniu.service.LogService;
import com.woniu.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("LogRecord")
public class LogController {

    @Resource
    private LogService logService;
    @Resource
    private UserService userService;

    /**
     *  登录跳转页面
     * @param model
     * @return
     */
    @RequestMapping("loglist")
    public String  loglist(Model model){
        //user列表
        List<User> userList=new ArrayList<>();
        userList=userService.findAll4workselect();
        model.addAttribute("userList", userList);
        return "/LogRecord/loglist";
    }

    /**
     *  日志列表
     * @param pageBean
     * @param log
     * @return
     */
    @RequestMapping("loglistDo")
    @ResponseBody
    public Map<String, Object> loglistDo(PageBean pageBean, Log log){
        Map<String, Object> resultMap = new HashMap<>();

        try {
            List<Log> logList=logService.getLogList(pageBean,log);
            resultMap.put("logList",logList);
            resultMap.put("pageBean", pageBean);
            resultMap.put("result", true);
        } catch (Exception e) {
            resultMap.put("result", false);
        }
         return resultMap;
    }
}

